﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sbook.Data;
using Sbook.Business;
namespace Sbook
{
    public partial class Product_Details : System.Web.UI.Page
    {
        protected string StrStatus = "";
        protected string Pnum = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!Page.IsPostBack)
            {
               
                //rp_MenuR.DataSource = Business.CategoryService.Category_GetByAll();
                //rp_MenuR.DataBind();
                if (Request.QueryString["Product"] !=null)
                {
                    string Id = Request.QueryString["Product"];
                    Pnum = Business.ProductsService.Products_GetById(Id)[0].PNumber.ToString();
                    if (Business.ProductsService.Products_GetById(Id)[0].PNumber != "0")
                        StrStatus = "Còn hàng";
                    else
                        StrStatus = "Hết hàng";
                    LoadDataToRequest(Id);
                    string CatId = Business.ProductsService.Products_GetById(Id)[0].CatId;
                    CatName = Business.CategoryService.Category_GetById(CatId)[0].cName;
                    PUName = Business.PublisherService.Publisher_GetById(Business.ProductsService.Products_GetById(Id)[0].PUId)[0].PName;
                }
                else
                {
                    return;
                }
            }
        }
        protected string CatName = "";
        protected string PUName = "";
        //protected void rpListParentProduct_ItemDataBound(object sender, RepeaterItemEventArgs e)
        //{
        //    Label CID = (Label)e.Item.FindControl("pID");
        //    Repeater rp_Chirld = (Repeater)e.Item.FindControl("rp_MenuRCh");
        //    if (CID != null && rp_Chirld != null)
        //    {
        //        rp_Chirld.DataSource = Business.CategoryService.Category_GetByAll().FindAll(c => c.cpID == CID.Text);
        //        rp_Chirld.DataBind();
        //    }
        //}

        private void LoadDataToRequest(string request)
        {
            
            //string Id = Request.QueryString["Product"];
            rptProDetail.DataSource =Business.ProductsService.FomatPrice(Business.ProductsService.Products_GetById(request));
            //rptProDetail.DataSource = Business.ProductsService.FormatSaleOff(Business.ProductsService.Products_GetById(request));
            rptProDetail.DataSource = Business.ProductsService.FomatPrice1(Business.ProductsService.FomatPrice(Business.ProductsService.Products_GetById(request)));
            rptProDetail.DataBind();
            rptProLienquan.DataSource=Business.ProductsService.Products_GetByAll().FindAll(p=>p.CatId==Business.ProductsService.Products_GetById(request)[0].CatId);
            rptProLienquan.DataBind();
        }
    }
}